﻿
namespace bookMaster.AssetSystem.Windows.Forms
{
	/// <summary>
	/// abstract Prueba typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class PruebaDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<PruebaDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.Prueba _currentPrueba = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxPruebaDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxPruebaErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxPruebaBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the IdPrueba property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIdPruebaDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Nombre property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxNombreDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Apellido property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxApellidoDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.Prueba> _PruebaList;
				
		/// <summary> 
		/// The list of Prueba to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.Prueba> PruebaList
		{
			get {return this._PruebaList;}
			set
			{
				this._PruebaList = value;
				this.uxPruebaBindingSource.DataSource = null;
				this.uxPruebaBindingSource.DataSource = value;
				this.uxPruebaDataGridView.DataSource = null;
				this.uxPruebaDataGridView.DataSource = this.uxPruebaBindingSource;				
				//this.uxPruebaBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxPruebaBindingSource_ListChanged);
				this.uxPruebaBindingSource.CurrentItemChanged += new System.EventHandler(OnPruebaBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnPruebaBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentPrueba = uxPruebaBindingSource.Current as Entities.Prueba;
			
			if (_currentPrueba != null)
			{
				_currentPrueba.Validate();
			}
			//_Prueba.Validate();
			OnCurrentEntityChanged();
		}

		//void uxPruebaBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.Prueba"/> instance.
		/// </summary>
		public Entities.Prueba SelectedPrueba
		{
			get {return this._currentPrueba;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxPruebaDataGridView.VirtualMode;}
			set
			{
				this.uxPruebaDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxPruebaDataGridView.AllowUserToAddRows;}
			set {this.uxPruebaDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxPruebaDataGridView.AllowUserToDeleteRows;}
			set {this.uxPruebaDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxPruebaDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxPruebaDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="PruebaDataGridViewBase"/> class.
		/// </summary>
		public PruebaDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxPruebaDataGridView = new System.Windows.Forms.DataGridView();
			this.uxPruebaBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxPruebaErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIdPruebaDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxNombreDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxApellidoDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxPruebaDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxPruebaBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxPruebaErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxPruebaErrorProvider
			// 
			this.uxPruebaErrorProvider.ContainerControl = this;
			this.uxPruebaErrorProvider.DataSource = this.uxPruebaBindingSource;						
			// 
			// uxPruebaDataGridView
			// 
			this.uxPruebaDataGridView.AutoGenerateColumns = false;
			this.uxPruebaDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxPruebaDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIdPruebaDataGridViewColumn,
		this.uxNombreDataGridViewColumn,
		this.uxApellidoDataGridViewColumn			});
			this.uxPruebaDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxPruebaDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxPruebaDataGridView.Name = "uxPruebaDataGridView";
			this.uxPruebaDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxPruebaDataGridView.TabIndex = 0;	
			this.uxPruebaDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxPruebaDataGridView.EnableHeadersVisualStyles = false;
			this.uxPruebaDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnPruebaDataGridViewDataError);
			this.uxPruebaDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnPruebaDataGridViewCellValueNeeded);
			this.uxPruebaDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnPruebaDataGridViewCellValuePushed);
			
			//
			// uxIdPruebaDataGridViewColumn
			//
			this.uxIdPruebaDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIdPruebaDataGridViewColumn.DataPropertyName = "IdPrueba";
			this.uxIdPruebaDataGridViewColumn.HeaderText = "IdPrueba";
			this.uxIdPruebaDataGridViewColumn.Name = "uxIdPruebaDataGridViewColumn";
			this.uxIdPruebaDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIdPruebaDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIdPruebaDataGridViewColumn.ReadOnly = true;		
			//
			// uxNombreDataGridViewColumn
			//
			this.uxNombreDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxNombreDataGridViewColumn.DataPropertyName = "Nombre";
			this.uxNombreDataGridViewColumn.HeaderText = "Nombre";
			this.uxNombreDataGridViewColumn.Name = "uxNombreDataGridViewColumn";
			this.uxNombreDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxNombreDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxNombreDataGridViewColumn.ReadOnly = false;		
			//
			// uxApellidoDataGridViewColumn
			//
			this.uxApellidoDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxApellidoDataGridViewColumn.DataPropertyName = "Apellido";
			this.uxApellidoDataGridViewColumn.HeaderText = "Apellido";
			this.uxApellidoDataGridViewColumn.Name = "uxApellidoDataGridViewColumn";
			this.uxApellidoDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxApellidoDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxApellidoDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxPruebaDataGridView);
			this.Name = "PruebaDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxPruebaErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxPruebaDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxPruebaBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				PruebaDataGridViewEventArgs args = new PruebaDataGridViewEventArgs();
				args.Prueba = _currentPrueba;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class PruebaDataGridViewEventArgs : System.EventArgs
		{
			private Entities.Prueba	_Prueba;
	
			/// <summary>
			/// the  Entities.Prueba instance.
			/// </summary>
			public Entities.Prueba Prueba
			{
				get { return _Prueba; }
				set { _Prueba = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxPruebaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnPruebaDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxPruebaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnPruebaDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxPruebaDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIdPruebaDataGridViewColumn":
						e.Value = PruebaList[e.RowIndex].IdPrueba;
						break;
					case "uxNombreDataGridViewColumn":
						e.Value = PruebaList[e.RowIndex].Nombre;
						break;
					case "uxApellidoDataGridViewColumn":
						e.Value = PruebaList[e.RowIndex].Apellido;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxPruebaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnPruebaDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxPruebaDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIdPruebaDataGridViewColumn":
						PruebaList[e.RowIndex].IdPrueba = (int)e.Value;
						break;
					case "uxNombreDataGridViewColumn":
						PruebaList[e.RowIndex].Nombre = (string)e.Value;
						break;
					case "uxApellidoDataGridViewColumn":
						PruebaList[e.RowIndex].Apellido = (string)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
